package cn.edu.tsc.controller;

import cn.edu.tsc.dao.EmpDao;
import cn.edu.tsc.pojo.Emp;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/SearchServlet")
public class SearchServlet extends HttpServlet {

//    public SearchServlet() {
//        super();
//    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String search = req.getParameter("search");

        if (search == null)
            return;

        EmpDao empDao = new EmpDao();
        List<Emp> emps = empDao.search(search);

        req.setAttribute("listEmp", emps);

        req.getRequestDispatcher("index.jsp").forward(req, resp);



    }
}
